<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>夏令营车辆管理模块</title>
    <link rel="stylesheet" href="./layui/css/layui.css">
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo layui-hide-xs layui-bg-black">车辆管理系统</div>
        <!-- 头部区域（可配合layui 已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">
            <!-- 移动端显示 -->
            <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-header-event="menuLeft">
                <i class="layui-icon layui-icon-spread-left"></i>
            </li>

            <li class="layui-nav-item layui-hide-xs"><a href="">人事系统</a></li>
            <li class="layui-nav-item layui-hide-xs"><a href="">档案系统</a></li>
            <li class="layui-nav-item layui-hide-xs"><a href="">行政系统</a></li>
            <li class="layui-nav-item">
                <a href="javascript:;">日志系统</a>
                <dl class="layui-nav-child">
                    <dd><a href="">日志</a></dd>
                    <dd><a href="">日志</a></dd>
                    <dd><a href="">日志服务器</a></dd>
                </dl>
            </li>
        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item layui-hide layui-show-md-inline-block">
                <a href="javascript:;">
                    <img src="./img/头像.jpg" class="layui-nav-img">
                    你的名字
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="">个人信息</a></dd>
                    <dd><a href="">修改密码</a></dd>
                    <dd><a href="">退出</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item" lay-header-event="menuRight" lay-unselect>
                <a href="javascript:;">
                    <i class="layui-icon layui-icon-more-vertical"></i>
                </a>
            </li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="test">
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="javascript:;">用户数据管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="department.html">部门管理</a></dd>
                        <dd><a href="role.html">职位管理</a></dd>
                        <dd class="layui-this"><a href="user.html">用户列表</a></dd>

                    </dl>
                </li>
                <li class="layui-nav-item layui-nav-itemed">
                    <a href="javascript:;">车辆数据管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="driver.html">驾驶员管理</a></dd>
                        <dd><a href="car.html">车辆信息管理</a></dd>
                        <dd><a href="">车辆预定管理</a></dd>
                        <dd><a href="">我的预定管理</a></dd>
                        <dd><a href="">车辆调度管理</a></dd>
                        <dd><a href="">车辆归还管理</a></dd>
                        <dd><a href="">出车记录管理</a></dd>
                    </dl>
                </li>

            </ul>
        </div>
    </div>

    <div class="layui-body">
        <!-- 内容主体区域 -->
        <div style="padding: 15px;">
            <!-- 内容主体区域  面包屑-->
            <span class="layui-breadcrumb">
              <a href="index.html">首页</a>
              <a><cite>用户数据管理</cite></a>
              <a><cite>用户管理</cite></a>
            </span>

            <!-- 水平线 -->
            <hr class="layui-bg-blue">

            <!-- 搜索条件 -->
            <fieldset class="layui-elem-field">
                <legend>筛选条件</legend>
                <div class="layui-field-box">
                    <div class="layui-form-item layui-form-pane">
                        <label class="layui-form-label">用户名</label>
                        <div class="layui-input-inline">
                            <input type="text" id="search_username" placeholder="请输入用户名" class="layui-input">
                        </div>

                        <label class="layui-form-label">手机号</label>
                        <div class="layui-input-inline">
                            <input type="text" id="search_phone" placeholder="请输入手机号" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item layui-form-pane">
                        <label class="layui-form-label">部门名称</label>
                        <div class="layui-inline">
                            <form class="layui-form">
                                <select name="quiz1" id="search_select_department">
                                    <option value="" selected>请选择部门</option>
                                </select>
                            </form>
                         </div>
                    </div>

                    <div class="layui-form-item layui-form-pane">
                        <label class="layui-form-label">职位名称</label>
                        <div class="layui-inline">
                            <form class="layui-form">
                                <select name="quiz2" id="search_select_role">
                                    <option value="" selected>请选择职位</option>
                                </select>
                            </form>
                        </div>
                    </div>

                    <div class="layui-form-item layui-form-pane">
                        <div class="layui-inline">
                            <button class="layui-btn layui-btn-radius layui-btn-warm" id="iReset">重置</button>
                            <button class="layui-btn layui-btn-radius layui-btn-normal" id="searchVal">搜索</button>
                        </div>
                    </div>

                </div>
            </fieldset>

            <table class="layui-hide" id="test001" lay-filter="test"></table>
        </div>
    </div>

    <div class="layui-footer">
        <!-- 底部固定区域 -->
        copyright©夏令营模块化工程  www.xxxxx.com
    </div>

    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
            <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
            <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
            <button class="layui-btn layui-btn-sm" lay-event="insertData">新增数据</button>
        </div>
    </script>

    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>

<!--添加用户窗口-->
    <script type="text/html" id="insert_form">
        <div class="layui-field-box">
            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-inline">
                    <input type="text" id="insert_username" class="layui-input" placeholder="请输入用户名">
                </div>
            </div>

            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-inline">
                    <input type="text" id="insert_password" class="layui-input" placeholder="请输入密码">
                </div>
            </div>

            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-inline">
                    <input type="text" id="insert_sex" class="layui-input" placeholder="请输入性别">
                </div>
            </div>

            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">身份证</label>
                <div class="layui-input-inline">
                    <input type="text" id="insert_card" class="layui-input" placeholder="请输入身份证号码">
                </div>
            </div>
            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">手机号</label>
                <div class="layui-input-inline">
                    <input type="text" id="insert_phone" class="layui-input" placeholder="请输入手机号">
                </div>
            </div>
            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">家庭住址</label>
                <div class="layui-input-inline">
                    <input type="text" id="insert_address" class="layui-input" placeholder="请输入家庭住址">
                </div>
            </div>
            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">职位名称</label>
                <div class="layui-inline">
                    <form class="layui-form">
                        <select name="quiz3" id="insert_role">
                            <option value="" selected>请选择职位</option>
                        </select>
                    </form>
                </div>
            </div>
            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">部门名称</label>
                <div class="layui-inline">
                    <form class="layui-form">
                        <select name="quiz3" id="insert_department">
                            <option value="" selected>请选择部门</option>
                        </select>
                    </form>
                </div>
            </div>
            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">创建时间</label>
                <div class="layui-input-inline">
                    <input type="date" id="insert_time" class="layui-input" placeholder="请选择时间">
                </div>
            </div>
        </div>
    </script>

<!--    更新用户窗口  -->
    <script type="text/html" id="update_form">

        <div class="layui-field-box">

            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-inline">
                    <input type="text" id="update_username" class="layui-input" placeholder="请输入用户名">
                </div>
            </div>

            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-inline">
                    <input type="text" id="update_password" class="layui-input" placeholder="请输入密码">
                </div>
            </div>

            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-inline">
                    <input type="text" id="update_sex" class="layui-input" placeholder="请输入性别">
                </div>
            </div>

            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">身份证</label>
                <div class="layui-input-inline">
                    <input type="text" id="update_card" class="layui-input" placeholder="请输入身份证号码">
                </div>
            </div>
            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">手机号</label>
                <div class="layui-input-inline">
                    <input type="text" id="update_phone" class="layui-input" placeholder="请输入手机号">
                </div>
            </div>
            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">家庭住址</label>
                <div class="layui-input-inline">
                    <input type="text" id="update_address" class="layui-input" placeholder="请输入家庭住址">
                </div>
            </div>

            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">职位名称</label>
                <div class="layui-inline">
                    <form class="layui-form">
                        <select name="quiz3" id="update_select_role">
                            <option value="" selected>请选择职位</option>
                        </select>
                    </form>
                </div>
            </div>
            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">部门名称</label>
                <div class="layui-inline">
                    <form class="layui-form">
                        <select name="quiz3" id="update_select_department">
                            <option value="" selected>请选择部门</option>
                        </select>
                    </form>
                </div>
            </div>

        </div>

    </script>
</div>

<script src="./layui/layui.js"></script>
<script src="jQuery/jquery-3.3.1.min.js"></script>
<script>

    let departmentNamesArray = [];
    $.ajax({
        url:"/department/selectDepartmentNames", //请求路径
        type:"get",//请求的方式，不区分大小写。
        cache:false,  //关闭缓存，目的是为了避免部分浏览器缓存加载出错（IE）
        datatype:"json",  //返回类型，text文本，HTML页面，JSON数据
        success:function (response) {
            console.log("返回："+response);
            if(response.code===0){
                departmentNamesArray = response.data;
                console.log(departmentNamesArray)
                for(i=0;i<departmentNamesArray.length;i++){
                    let onlyDepartment = departmentNamesArray[i]
                    $("#search_select_department").append("<option value='"+onlyDepartment.id+"'>"+onlyDepartment.departmentName+"</option>");
                }
                flushSelect();
            }
        },
        error:function (response){
            console.log("出错返回："+response);
        }
    });

    let roleNamesArray = [];
    $.ajax({
        url: "/role/selectRoleNames",
        type: "get",
        cache: false,
        datatype: "json",
        success: function (response) {
            console.log("返回：" + response);
            if (response.code === 0) {
                roleNamesArray = response.data;
                console.log(roleNamesArray);
                for (i = 0; i < roleNamesArray.length; i++) {
                    let onlyRole = roleNamesArray[i];
                    $("#search_select_role").append("<option value='" + onlyRole.id + "'>" + onlyRole.roleName + "</option>");
                    $("#update_roleName").append("<option value='" + onlyRole.id + "'>" + onlyRole.roleName + "</option>");
                }
                flushSelect();
            }

        },
        error: function (response) {
            console.log("出错返回：" + response);
        }
    });



<!--    重置按钮  -->
    $("#iReset").click(function () {
        $("#search_username").val("");  // 设置空值
        $("#search_phone").val("");
        $("#search_select_department").val();
        flushTable();
    });

function flushSelect() {
    //☆ 一定要记得，layUI的select重新装载以后，一定要通过此方法执行一次重新渲染，否则，select不会有效果
    layui.use('form',function () {
        var form = layui.form;
        form.render('select');
    });
}

    //查询按钮
    $("#searchVal").click(function () {
        let username = $("#search_username").val();  // 获取值，那么在val方法中，不能传入内容
        let phone = $("#search_phone").val();
        let select_department = $("#search_select_department").val();
        let select_role = $('#search_select_role').val();
        let json = {};
        if(username != null && username != '') {
            json.username = username;                 // 动态为一个json对象，添加一个key值，并且在此key值中添加指定的value值
        }
        if(phone != null && phone != '') {
            json.phone = phone;                 // 动态为一个json对象，添加一个key值，并且在此key值中添加指定的value值
        }
        if(select_department!=null && select_department!=''){
            json.departmentId = select_department;
        }
        if(select_role!=null && select_role!=''){
            json.roleId = select_role;
        }
        console.log(JSON.stringify(json));
        flushTable(json);
        // http://localhost:8080/user/selectUserList?page=1&limit=10&userName=%E6%8A%80%E6%9C%AF%E9%83%A8&userIdCard=10000
        // https://www.baidu.com/s?wd=%E6%B5%8B%E8%AF%95
    });

    layui.use('form', function(){ //此段代码必不可少
        var form = layui.form;
        form.render();
    });

    function flushTable(json) {
        layui.use('table', function(){
            var table = layui.table;

            table.render({             // 动态请求后台接口服务，完成数据渲染
                elem: '#test001'          // 渲染到指定id的table标签中
                ,url:'/user/selectUserList'
                ,where: json                  // layui中 where属性可以传递一个json参数，此参数默认是key-value关系，不是真正的json对象 ★★★
                ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                    title: '提示'
                    ,layEvent: 'LAYTABLE_TIPS'
                    ,icon: 'layui-icon-tips'
                }]
                ,title: '用户数据表'
                ,cols: [[
                    {type: 'checkbox', fixed: 'left'}
                    ,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true, templet: function(res){
                            return '<em>'+ res.id +'</em>'
                        }}
                    ,{field:'username', title:'用户名', width:100, templet: function(res){
                            return '<em>'+ res.username +'</em>'
                        }}
                    ,{field:'password', title:'密码', width:100, templet: function(res){
                            return '<em>'+ res.password +'</em>'
                        }}
                    ,{field:'sex', title:'性别', width:80, templet: function(res){
                            return '<em>'+ res.sex +'</em>'
                        }}
                    ,{field:'Card', title:'身份证号码', width:180, templet: function(res){
                            return '<em>'+ res.card +'</em>'
                        }}
                    ,{field:'phone', title:'电话号码', width:150, templet: function(res){
                            return '<em>'+ res.phone +'</em>'
                        }}
                    ,{field:'address', title:'家庭住址', width:150, templet: function(res){
                            return '<em>'+ res.address +'</em>'
                        }}
                    ,{field:'address', title:'创建时间', width:230, templet: function(res){
                            return '<em>'+ res.createTime +'</em>'
                        }}
                    ,{field:'departmentId', title:'部门名称', width:100, templet: function(res){
                            return '<em>'+ res.department.departmentName +'</em>'
                        }}
                    ,{field:'roleId', title:'职位名称', width:100, templet: function(res){
                            return '<em>'+ res.role.roleName +'</em>'
                        }}
                    ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
                ]]
                ,page: true
            });

            /*
            [{"id":1,"userName":"技术部","userIdCard":"10000"},
            {"id":2,"userName":"测试部","userIdCard":"10001"},
            {"id":3,"userName":"产品部","userIdCard":"10002"},
            {"id":4,"userName":"人事部","userIdCard":"10003"},
            {"id":5,"userName":"经理部","userIdCard":"10004"}]
             */

            //头工具栏事件
            table.on('toolbar(test)', function(obj){
                var checkStatus = table.checkStatus(obj.config.id);
                switch(obj.event){
                    case 'getCheckData':
                        var data = checkStatus.data;
                        layer.alert(JSON.stringify(data));
                        break;
                    case 'getCheckLength':
                        var data = checkStatus.data;
                        layer.msg('选中了：'+ data.length + ' 个');
                        break;
                    case 'isAll':
                        layer.msg(checkStatus.isAll ? '全选': '未全选');
                        break;
                    case 'insertData': {
                        let departmentNamesArray = [];
                        $.ajax({
                            url: "/department/selectDepartmentNames", //请求路径
                            type: "post",  //请求的方式，不区分大小写。
                            cache: false,  //关闭缓存，目的是为了避免部分浏览器缓存加载出错（IE）
                            datatype: "json",  //返回类型，text文本，HTML页面，JSON数据
                            success: function (response) {
                                console.log("返回：" + response);
                                if (response.code === 0) {
                                    departmentNamesArray = response.data;
                                    console.log(departmentNamesArray)
                                    for (i = 0; i < departmentNamesArray.length; i++) {
                                        let onlyDepartment = departmentNamesArray[i]
                                        $("#insert_department").append("<option value='" + onlyDepartment.id + "'>" + onlyDepartment.departmentName + "</option>");
                                    }
                                    flushSelect();
                                }
                            },
                            error: function (response) {
                                console.log("出错返回：" + response);
                            }
                        });

                        let roleNamesArray = [];
                        $.ajax({
                            url: "/role/selectRoleNames",
                            type: "post",
                            cache: false,
                            datatype: "json",
                            success: function (response) {
                                console.log("返回：" + response);
                                if (response.code === 0) {
                                    roleNamesArray = response.data;
                                    console.log(roleNamesArray);
                                    for (i = 0; i < roleNamesArray.length; i++) {
                                        let onlyRole = roleNamesArray[i];
                                        $("#insert_role").append("<option value='" + onlyRole.id + "'>" + onlyRole.roleName + "</option>");
                                   }
                                    flushSelect();
                                }
                            },
                            error: function (response) {
                                console.log("出错返回：" + response);
                            }
                        });

                        layer.open({     // 弹出框处理  模态框
                            type: 1               // 模态框
                            , title: '新增用户' //不显示标题栏
                            , closeBtn: false
                            , area: ['500px', '500px']  // 宽和高
                            , shade: 0.5
                            , id: 'LAY_layuipro' //设定一个id，防止重复弹出
                            , btn: ['新增', '取消']
                            , btnAlign: 'c'
                            , moveType: 1 //拖拽模式，0或者1
                            , content: $('#insert_form').html()         // 引入自定义表单
                            , btn1: function (index, layero) {            // 这个是新增按钮点击事件
                                let username = $("#insert_username").val();
                                let password = $("#insert_password").val();
                                let sex = $("#insert_sex").val();
                                let card = $("#insert_card").val();
                                let phone = $("#insert_phone").val();
                                let address = $("#insert_address").val();
                                let roleId = $("#insert_role").val();
                                let departmentId = $("#insert_department").val();
                                let createTime = $("#insert_time").val();
                                $.ajax({
                                    url: "/user/insert",           // 请求路径
                                    type: "post",                  // 请求的方式，不区分大小写
                                    cache: false,                  // 关闭缓存，目的是为了避免部分浏览器缓存加载出错(IE)
                                    contentType: "application/json;charset=utf-8",
                                    data: JSON.stringify({
                                        username: username,
                                        password: password,
                                        sex: sex,
                                        card: card,
                                        phone: phone,
                                        address: address,
                                        roleId:roleId,
                                        departmentId:departmentId,
                                        createTime:createTime
                                    }),
                                    datatype: "json",        // 返回类型，text文本、html页面、json数据
                                    success: function (response) {
                                        console.log("返回: " + response);
                                        if (response.code === 0) {
                                            console.log("新增成功")
                                            console.log(createTime)
                                            layer.msg("新增数据成功!");
                                            layer.close(index);                         // 关闭当前窗口
                                            flushTable();
                                        }
                                    },
                                    error: function (response) {
                                        console.log(typeof createTime)
                                        console.log("出错返回: " + response);
                                    }
                                });
                            }
                            , success: function (layero) {
                            }
                        });
                    }
                        break;

                    //自定义头工具栏右侧图标 - 提示
                    case 'LAYTABLE_TIPS':
                        layer.alert('这是工具栏右侧自定义的一个图标按钮');
                        break;
                };
            });

            //监听行工具事件
            table.on('tool(test)', function(obj){
                var data = obj.data;
                console.log(JSON.stringify(data));
                if(obj.event === 'del'){
                    layer.confirm('真的删除行么', function(index){
                        // 添加ajax删除代码
                        $.ajax({
                            url:"/user/delete",            // 请求路径
                            type:"post",                         // 请求的方式，不区分大小写
                            cache:false,                         // 关闭缓存，目的是为了避免部分浏览器缓存加载出错(IE)
                            data: {
                                id: data.id
                            },
                            datatype:"json",        // 返回类型，text文本、html页面、json数据
                            success:function(response){
                                if(response.code === 200) {
                                    layer.msg(response.msg);
                                    // 执行成功之后的流程
                                    flushTable();
                                }
                                else {
                                    alert(response.msg);
                                    // 执行出错之后的流程
                                }
                                console.log("返回: " + response);
                            },
                            error:function(response){
                                console.log("出错返回: " + response);
                            }
                        });
                        layer.close(index);
                    });
                } else if(obj.event === 'edit'){

                    let roleNamesArray = [];
                    $.ajax({
                        url: "/role/selectRoleNames",
                        type: "get",
                        cache: false,
                        datatype: "json",
                        success: function (response) {
                            console.log("返回：" + response);
                            if (response.code === 0) {
                                roleNamesArray = response.data;
                                console.log(roleNamesArray);
                                for (i = 0; i < roleNamesArray.length; i++) {
                                    let onlyRole = roleNamesArray[i];
                                    $("#update_select_role").append("<option value='" + onlyRole.id + "'>" + onlyRole.roleName + "</option>");
                                }
                                flushSelect();
                            }

                        },
                        error: function (response) {
                            console.log("出错返回：" + response);
                        }
                    });

                    $.ajax({
                        url:"/department/selectDepartmentNames", //请求路径
                        type:"get",//请求的方式，不区分大小写。
                        cache:false,  //关闭缓存，目的是为了避免部分浏览器缓存加载出错（IE）
                        datatype:"json",  //返回类型，text文本，HTML页面，JSON数据
                        success:function (response) {
                            console.log("返回："+response);
                            if(response.code===0){
                                departmentNamesArray = response.data;
                                console.log(departmentNamesArray)
                                for(i=0;i<departmentNamesArray.length;i++){
                                    let onlyDepartment = departmentNamesArray[i]
                                    $("#update_select_department").append("<option value='"+onlyDepartment.id+"'>"+onlyDepartment.departmentName+"</option>");
                                }
                                flushSelect();
                            }
                        },
                        error:function (response){
                            console.log("出错返回："+response);
                        }
                    });

                    layer.open({     // 弹出框处理  模态框
                        type: 1               // 模态框
                        ,title: '更新用户信息' //不显示标题栏
                        ,closeBtn: false
                        ,area: ['500px','500px']  // 宽和高
                        ,shade: 0.5
                        ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
                        ,btn: ['更新', '取消']
                        ,btnAlign: 'c'
                        ,moveType: 1 //拖拽模式，0或者1
                        ,content: $('#update_form').html()         // 引入自定义表单
                        ,btn1: function(index, layero){            // 这个是新增按钮点击事件
                            
                            let username = $("#update_username").val();
                            let password = $("#update_password").val();
                            let sex = $("#update_sex").val();
                            let card = $("#update_card").val();
                            let phone = $("#update_phone").val();
                            let address = $("#update_address").val();
                            let roleId = $("#update_select_role").val();
                            let departmentId = $("#update_select_department").val();

                            $.ajax({
                                url:"/user/update",           // 请求路径
                                type:"post",                  // 请求的方式，不区分大小写
                                cache:false,                  // 关闭缓存，目的是为了避免部分浏览器缓存加载出错(IE)
                                contentType:"application/json;charset=utf-8",
                                data: JSON.stringify({
                                    id:data.id,
                                    username:username,
                                    password:password,
                                    sex:sex,
                                    card:card,
                                    phone:phone,
                                    address:address,
                                    roleId:roleId,
                                    departmentId:departmentId
                                }),
                                datatype:"json",        // 返回类型，text文本、html页面、json数据
                                success:function(response){
                                    console.log("返回: " + response);
                                    if(response.code === 200) {
                                        layer.msg("更新数据成功!");
                                        layer.close(index);                         // 关闭当前窗口
                                        flushTable();
                                    }
                                },
                                error:function(response){
                                    console.log("出错返回: " + response);
                                }
                            });
                        }
                        ,success: function(layero){
                            console.log("123")
                            console.log(data)
                            $("#update_username").val(data.username);
                            $("#update_password").val(data.password);
                            $("#update_sex").val(data.sex);
                            $("#update_card").val(data.card);
                            $("#update_phone").val(data.phone);
                            $("#update_address").val(data.address);
                        }
                    });
                }
            });
        });
    }

    flushTable();

</script>
</body>
</html>